﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProgNetComponentsDx.Browsers;
using ProgNetComponentsDx.Language;
using System.ComponentModel;
using ProgNetComponents.Design.Attributes;

namespace ProgNetComponentsDx.Validation.Rules
{
    public class BrowserUniqueValidationRule : BrowserValidationRule
    {
        #region Static
        static BrowserUniqueValidationRule()
        {
            GlobalDefaultErrorString = "Ta wartość powinna być unikalna.";
        }
        public static string GlobalDefaultErrorString { get; set; }
        #endregion

        #region Properties
        protected override string DefaultErrorString
        {
            get
            {
                return GlobalDefaultErrorString;
            }
        }
        #endregion
        public BrowserUniqueValidationRule()
        {
        }
        public BrowserUniqueValidationRule(string column, object browserId, string error = null)
            : base(column, browserId, error)
        {
        }

        protected override bool DoValidate(System.Data.DataRow row)
        {
            bool result = !IsValueValid(row);
            return result;
        }
       
    }

    /// <summary>
    /// Validation rule for value unique in browser.
    /// Set BrowserUniqueValidationRuleLng.GlobalDefaultErrorStringLng for global validation error message (language specific)
    /// Set BrowserUniqueValidationRuleLng.GlobalDefaultErrorStringNoLng for global validation error message (not language specific)
    /// </summary>
    public class BrowserUniqueValidationRuleLng : BrowserUniqueValidationRule
    {
        #region Static
        static BrowserUniqueValidationRuleLng()
        {
            GlobalDefaultErrorStringNoLng = "Wartość z pola [{0}] powinna być unikalna.";
        }
        public static string GlobalDefaultErrorStringLng { get; set; }
        public static string GlobalDefaultErrorStringNoLng { get; set; }
        #endregion

        protected override string DefaultErrorString
        {
            get
            {
                return GlobalDefaultErrorStringLng;
            }
        }
       
        /// <summary>
        /// Gets formatted error string
        /// </summary>
        public override string FormatedErrorString
        {
            get
            {
                string str = ProgNetLanguage.sGetStringDefault(ErrorString, GlobalDefaultErrorStringNoLng, ProgNetLanguage.sGetStringDefault(Column, Column));
                return str;
            }
        }
        public BrowserUniqueValidationRuleLng()
        {

        }
        public BrowserUniqueValidationRuleLng(string column, object browserId, string error = null):base(column, browserId, error)
        {

        }
        
    }
}
